package com.corona;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.Controllers;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.TextureData;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.corona.game.*;
import com.corona.leaks.LeakTracer;
import com.corona.updater.VersionControl;
import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Server;
import com.esotericsoftware.minlog.Log;
import com.corona.game.util.GameProfiler;
import com.corona.game.util.ProxyBatch;
import com.corona.game.util.SpriteProxy;
import com.corona.game.util.TextureCache;
import com.sun.jna.platform.win32.WinError;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import org.zeroturnaround.zip.commons.IOUtils;

/* loaded from: pokewilds.jar:com/pkmngen/game/Game.class */
public class Game extends ApplicationAdapter {
    public static Game staticGame;
    public static LeakTracer leakTracer;
    public ArrayList<Action> actionStack;
    public ArrayList<Action> actionStackCopy;
    public ProxyBatch mapBatch;
    public ProxyBatch uiBatch;
    public BitmapFont font;
    public OrthographicCamera cam;
    private ScreenViewport viewport;
    public Vector3 touchLoc;
    public boolean playerCanMove;
    public Action displayTextAction;
    public Vector2 currScreen;
    public boolean debugInputEnabled;
    public boolean dangerousDebugInputEnabled;
    public Player player;
    public PkmnMap map;
    public Battle battle;
    public Music currMusic;
    public MusicController musicController;
    public HashMap<String, Music> loadedMusic;
    public HashMap<String, Sound> loadedSound;
    public Map<Character, SpriteProxy> textDict;
    public HashMap<Character, SpriteProxy> transparentDict;
    public HashMap<String, Player> players;
    public HashMap<String, Battle> battles;
    public VersionControl versionControl;
    private boolean skipUpdateCheck;
    public Texture cloudTexture;
    public Texture nightTexture;
    public Texture currCloudTexture;
    public Texture islandTexture;
    public Color currSunsetColor;
    public Color prevColor;
    public Vector2 cloudOffset;
    int rippleTimer;
    public Vector2 startPos;
    public Vector2 endPos;
    boolean otherFlipY;
    public Client client;
    public Server server;
    public Type type;
    public Thread gameThread;
    public DrawCampfireAuras drawCampfireAuras;
    public Texture shadow;
    public FrameBuffer frameBuffer;
    public boolean levelScalingEnabled;
    public HashMap<Character, SpriteProxy> brailleDict;
    public HashMap<Character, SpriteProxy> textDictInverse;
    public boolean cinematic;
    public long startTime;
    public long currTime;
    public HashMap<String, Long> timings;
    public ArrayList<String> alreadyUsedDungeons;
    public int temp1;
    public int temp2;
    public int scale;
    public static Controller gamepad;
    public int shinyRate;
    private GameProfiler profiler;
    private final GridPoint2 oldWindowSize;
    private boolean inFullScreen;
    public static Random rand = new Random();
    public static boolean fairyTypeEnabled = true;
    public static boolean catchExpEnabled = true;
    public static boolean specialPhysicalSplitEnabled = true;
    public static boolean musicDisabled = false;
    public static boolean photosensitiveMode = true;
    public static boolean battleAnims = true;
    public static TextSpeed textSpeed = TextSpeed.MID;
    public static boolean drawReflections = true;
    public static boolean drawOverlays = true;
    public static Matrix4 identity = new Matrix4();
    public static boolean canUseFrameBuffers = true;
    public static String[][] defaultSettings = {new String[]{"keyboard-A", "Z"}, new String[]{"keyboard-B", "X"}, new String[]{"keyboard-Left", "Left"}, new String[]{"keyboard-Right", "Right"}, new String[]{"keyboard-Up", "Up"}, new String[]{"keyboard-Down", "Down"}, new String[]{"keyboard-Start", "Enter"}, new String[]{"keyboard-L", "C"}, new String[]{"keyboard-R", "V"}, new String[]{"muteMusic", "false"}, new String[]{"specPhysSplitEnabled", "true"}, new String[]{"photosensitiveMode", "true"}, new String[]{"battleAnims", "true"}, new String[]{"textSpeed", "mid"}, new String[]{"gamepad-A", "A"}, new String[]{"gamepad-B", "B"}, new String[]{"gamepadDeadZone", "0.3"}, new String[]{"zoom", "1.0"}, new String[]{"drawReflections", "true"}, new String[]{"drawOverlays", "true"}};
    public static List<String> evoStones = new ArrayList();

    /* loaded from: pokewilds.jar:com/pkmngen/game/Game$CacheLayer.class */
    public enum CacheLayer {
        FireAuras,
        Reflections
    }

    /* access modifiers changed from: package-private */
    /* loaded from: pokewilds.jar:com/pkmngen/game/Game$Type.class */
    public enum Type {
        CLIENT,
        SERVER
    }

    static {
        evoStones.add("water stone");
        evoStones.add("fire stone");
        evoStones.add("leaf stone");
        evoStones.add("thunderstone");
        evoStones.add("moon stone");
        evoStones.add("sun stone");
        evoStones.add("ice stone");
        evoStones.add("dawn stone");
        evoStones.add("dusk stone");
        evoStones.add("shiny stone");
        evoStones.add("sweet apple");
    }

    public Game() {
        this.actionStack = new ArrayList<>();
        this.actionStackCopy = new ArrayList<>();
        this.touchLoc = new Vector3();
        this.currScreen = new Vector2();
        this.debugInputEnabled = false;
        this.dangerousDebugInputEnabled = false;
        this.musicController = null;
        this.loadedMusic = new HashMap<>();
        this.loadedSound = new HashMap<>();
        this.transparentDict = new HashMap<>();
        this.players = new HashMap<>();
        this.battles = new HashMap<>();
        this.versionControl = new VersionControl();
        this.skipUpdateCheck = false;
        this.currSunsetColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
        this.prevColor = new Color();
        this.cloudOffset = new Vector2(0.0f, 0.0f);
        this.rippleTimer = 0;
        this.startPos = new Vector2();
        this.endPos = new Vector2();
        this.otherFlipY = false;
        this.levelScalingEnabled = true;
        this.brailleDict = new HashMap<>();
        this.textDictInverse = new HashMap<>();
        this.cinematic = false;
        this.startTime = 0;
        this.currTime = 0;
        this.timings = new HashMap<>();
        this.alreadyUsedDungeons = new ArrayList<>();
        this.scale = 3;
        this.shinyRate = 256;
        this.oldWindowSize = new GridPoint2();
        this.inFullScreen = false;
    }

    public Game(String[] args, int scale) {
        this();
        for (String arg : args) {
            char c = 65535;
            switch (arg.hashCode()) {
                case -1216167350:
                    if (arg.equals("dangerous")) {
                        c = 3;
                        break;
                    }
                    break;
                case 98504:
                    if (arg.equals("cin")) {
                        c = 1;
                        break;
                    }
                    break;
                case 99349:
                    if (arg.equals("dev")) {
                        c = 0;
                        break;
                    }
                    break;
                case 912621248:
                    if (arg.equals("skipUpdateCheck")) {
                        c = 2;
                        break;
                    }
                    break;
            }
            switch (c) {
                case 0:
                    this.debugInputEnabled = true;
                    break;
                case 1:
                    this.cinematic = true;
                    break;
                case 2:
                    this.skipUpdateCheck = true;
                    break;
                case 3:
                    this.dangerousDebugInputEnabled = true;
                    this.debugInputEnabled = true;
                    break;
            }
        }
        this.scale = scale;
    }

    public static ArrayList<String> readLines(FileHandle file) throws IOException {
        Reader reader = file.reader();
        BufferedReader br = new BufferedReader(reader);
        ArrayList<String> lines = new ArrayList<>();
        while (true) {
            String line = br.readLine();
            if (line != null) {
                lines.add(line);
            } else {
                reader.close();
                return lines;
            }
        }
    }

    @Override // com.badlogic.gdx.ApplicationAdapter, com.badlogic.gdx.ApplicationListener
    public void create() {
        this.profiler = new GameProfiler(this.debugInputEnabled);
        staticGame = this;
        this.gameThread = Thread.currentThread();
        this.mapBatch = new ProxyBatch();
        this.uiBatch = new ProxyBatch();
        this.mapBatch.enableBlending();
        this.uiBatch.enableBlending();
        this.mapBatch.setBlendFunction(770, 771);
        this.uiBatch.setBlendFunction(770, 771);
        try {
            this.frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, WinError.ERROR_MULTIPLE_FAULT_VIOLATION, 432, false);
        } catch (GdxRuntimeException e) {
            canUseFrameBuffers = false;
            System.out.println("WARNING: Frame Buffers not supported.");
        }
        this.drawCampfireAuras = new DrawCampfireAuras(this);
        this.shadow = TextureCache.get(Gdx.files.internal("shadow2.png"));
        this.cam = new OrthographicCamera(160.0f, 144.0f);
        this.cam.position.set(16.0f, 0.0f, 0.0f);
        this.cam.zoom = 1.0f;
        this.viewport = new ScreenViewport(this.cam);
        FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal("fonts.ttf"));
        FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        parameter.size = 10;
        this.font = gen.generateFont(parameter);
        this.font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
        this.font.setColor(Color.BLACK);
        this.player = new Player();
        this.battle = new Battle();
        this.textDict = initTextDict();
        initTransparentDict();
        initBrailleDict();
        initInverseTextDict();
        insertAction(new InputProcessor());
        if (Gdx.app.getType() == Application.ApplicationType.Android) {
            insertAction(new DrawMobileControls(this));
        }
        insertAction(new DrawSetupMenu(this, null));
        ScreenUtils.clear(1.0f, 1.0f, 1.0f, 1.0f, true);
        ShaderProgram.pedantic = false;
        System.out.println("Java version info");
        System.out.println(System.getProperty("java.version"));
        System.out.println(System.getProperty("java.specification.version"));
        System.out.println("Graphics processor info");
        System.out.println(Gdx.gl.glGetString(7936));
        System.out.println(Gdx.gl.glGetString(7937));
        System.out.println("OpenGL info");
        System.out.println(Gdx.gl.glGetString(7938));
        this.cloudTexture = TextureCache.get(Gdx.files.local("cloud5.png"));
        this.nightTexture = TextureCache.get(Gdx.files.local("stars1.png"));
        this.currCloudTexture = this.cloudTexture;
        this.islandTexture = TextureCache.get(Gdx.files.local("island1.png"));
        if (this.skipUpdateCheck) {
            this.versionControl.checkVersion();
        }
        gamepad = Controllers.getCurrent();
        try {
            loadSettings(Gdx.files.local("settings.txt"));
        } catch (GdxRuntimeException e2) {
            String settingsString = "";
            for (int i = 0; i < defaultSettings.length; i++) {
                settingsString = settingsString + defaultSettings[i][0] + "=" + defaultSettings[i][1];
                if (i < defaultSettings.length - 1) {
                    settingsString = settingsString + IOUtils.LINE_SEPARATOR_WINDOWS;
                }
            }
            try {
                FileHandle file = Gdx.files.local("settings.txt");
                file.writeString(settingsString, false);
                loadSettings(file);
            } catch (GdxRuntimeException err) {
                err.printStackTrace();
            }
        }
        this.viewport.setUnitsPerPixel(1.0f / ((float) this.scale));
        System.out.print("Frame Buffers enabled: ");
        System.out.println(canUseFrameBuffers);
    }

    public boolean isMapLoaded() {
        return this.map != null;
    }

    public void saveGame() {
        if (this.map != null) {
            this.map.saveToFileNew(this);
        }
    }

    @Override // com.badlogic.gdx.ApplicationAdapter, com.badlogic.gdx.ApplicationListener
    public void dispose() {
        this.mapBatch.dispose();
        this.uiBatch.dispose();
        for (Music music : this.loadedMusic.values()) {
            music.dispose();
        }
        for (Sound sound : this.loadedSound.values()) {
            sound.dispose();
        }
        if (this.server != null) {
            this.server.close();
        }
        if (this.type == Type.CLIENT) {
            this.client.sendTCP(new Network.Logout(this.player.network.id));
        }
    }

    /*  JADX ERROR: JadxRuntimeException in pass: BlockProcessor
        jadx.core.utils.exceptions.JadxRuntimeException: Unreachable block: B:165:0x0694
        	at jadx.core.dex.visitors.blocks.BlockProcessor.checkForUnreachableBlocks(BlockProcessor.java:86)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.processBlocksTree(BlockProcessor.java:52)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.visit(BlockProcessor.java:44)
        */
    private void handleDebuggingInput() {
        /*
        // Method dump skipped, instructions count: 2652
        */
        throw new UnsupportedOperationException("Method not decompiled: com.corona.Game.handleDebuggingInput():void");
    }

    private Pixmap createPixmap(Map<String, Pixmap> pixmapCache, String name) {
        if (!pixmapCache.containsKey(name)) {
            TextureData temp = TextureCache.get(Gdx.files.internal(name)).getTextureData();
            if (!temp.isPrepared()) {
                temp.prepare();
            }
            pixmapCache.put(name, temp.consumePixmap());
        }
        return pixmapCache.get(name);
    }

    public void initClient(String ip) throws IOException {
        if (this.client != null) {
            this.client.close();
        }
        this.client = new Client();
        this.type = Type.CLIENT;
        Network.register(this.client);
        this.client.start();
        try {
            this.client.connect(5000, ip, Network.port);
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.player.network.id = this.player.name;
        this.player.type = Player.Type.LOCAL;
        this.map.tiles.clear();
        this.client.sendTCP(new Network.Login(this.player.network.id, this.player.color));
        insertAction(new ClientBroadcast(this));
    }

    public void initServer() throws IOException {
        this.server = new Server();
        Network.register(this.server);
        this.type = Type.SERVER;
        this.server.bind(Network.port);
        this.server.start();
        while (this.server.getUpdateThread() == null) {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void initTransparentDict() {
        Texture text = TextureCache.get(Gdx.files.internal("text_sheet1_transparent.png"));
        char[] alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
        char[] alphabet_lower = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        for (int i = 0; i < 26; i++) {
            this.transparentDict.put(Character.valueOf(alphabet_upper[i]), new SpriteProxy(text, 10 + (16 * i), 5, 8, 8));
        }
        for (int i2 = 0; i2 < 26; i2++) {
            this.transparentDict.put(Character.valueOf(alphabet_lower[i2]), new SpriteProxy(text, 10 + (16 * i2), 17, 8, 8));
        }
        for (int i3 = 0; i3 < 10; i3++) {
            this.transparentDict.put(Character.valueOf(Character.forDigit(i3, 10)), new SpriteProxy(text, 10 + (16 * i3), 29, 8, 8));
        }
        this.transparentDict.put(' ', new SpriteProxy(text, 170, 29, 8, 8));
        this.transparentDict.put('<', new SpriteProxy(text, 10, 41, 8, 8));
        this.transparentDict.put('>', new SpriteProxy(text, 26, 41, 8, 8));
        this.transparentDict.put('_', new SpriteProxy(text, 42, 41, 8, 8));
        this.transparentDict.put('?', new SpriteProxy(text, 58, 41, 8, 8));
        this.transparentDict.put('!', new SpriteProxy(text, 74, 41, 8, 8));
        this.transparentDict.put('.', new SpriteProxy(text, 122, 41, 8, 8));
        this.transparentDict.put(',', new SpriteProxy(text, 138, 41, 8, 8));
        this.transparentDict.put((char) 233, new SpriteProxy(text, 154, 41, 8, 8));
        this.transparentDict.put((char) 201, new SpriteProxy(text, 154, 41, 8, 8));
        this.transparentDict.put('-', new SpriteProxy(text, 170, 41, 8, 8));
        this.transparentDict.put('\'', new SpriteProxy(text, 186, 41, 8, 8));
        this.transparentDict.put((char) 236, new SpriteProxy(text, 202, 41, 8, 8));
        this.transparentDict.put((char) 146, new SpriteProxy(text, 136, 45, 8, 8));
        this.transparentDict.put(null, new SpriteProxy(text, 10, 53, 8, 8));
    }

    public void initBrailleDict() {
        Texture text = TextureCache.get(Gdx.files.internal("braille_sheet1.png"));
        char[] alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
        char[] alphabet_lower = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        for (int i = 0; i < 26; i++) {
            this.brailleDict.put(Character.valueOf(alphabet_upper[i]), new SpriteProxy(text, 10 + (16 * i), 5, 8, 8));
        }
        for (int i2 = 0; i2 < 26; i2++) {
            this.brailleDict.put(Character.valueOf(alphabet_lower[i2]), new SpriteProxy(text, 10 + (16 * i2), 5, 8, 8));
        }
    }

    public void initInverseTextDict() {
        Texture text = TextureCache.get(Gdx.files.internal("text_sheet1_transparent_inverse.png"));
        char[] alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
        char[] alphabet_lower = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        for (int i = 0; i < 26; i++) {
            this.textDictInverse.put(Character.valueOf(alphabet_upper[i]), new SpriteProxy(text, 10 + (16 * i), 5, 8, 8));
        }
        for (int i2 = 0; i2 < 26; i2++) {
            this.textDictInverse.put(Character.valueOf(alphabet_lower[i2]), new SpriteProxy(text, 10 + (16 * i2), 17, 8, 8));
        }
        for (int i3 = 0; i3 < 10; i3++) {
            this.textDictInverse.put(Character.valueOf(Character.forDigit(i3, 10)), new SpriteProxy(text, 10 + (16 * i3), 29, 8, 8));
        }
        this.textDictInverse.put(' ', new SpriteProxy(text, 170, 29, 8, 8));
        this.textDictInverse.put('<', new SpriteProxy(text, 10, 41, 8, 8));
        this.textDictInverse.put('>', new SpriteProxy(text, 26, 41, 8, 8));
        this.textDictInverse.put('_', new SpriteProxy(text, 42, 41, 8, 8));
        this.textDictInverse.put('?', new SpriteProxy(text, 58, 41, 8, 8));
        this.textDictInverse.put('!', new SpriteProxy(text, 74, 41, 8, 8));
        this.textDictInverse.put('.', new SpriteProxy(text, 122, 41, 8, 8));
        this.textDictInverse.put(',', new SpriteProxy(text, 138, 41, 8, 8));
        this.textDictInverse.put((char) 233, new SpriteProxy(text, 154, 41, 8, 8));
        this.textDictInverse.put((char) 201, new SpriteProxy(text, 154, 41, 8, 8));
        this.textDictInverse.put('-', new SpriteProxy(text, 170, 41, 8, 8));
        this.textDictInverse.put('\'', new SpriteProxy(text, 186, 41, 8, 8));
        this.textDictInverse.put((char) 236, new SpriteProxy(text, 202, 41, 8, 8));
        this.textDictInverse.put((char) 146, new SpriteProxy(text, 136, 45, 8, 8));
        this.transparentDict.put((char) 205, new SpriteProxy(text, 136, 49, 8, 8));
        this.textDictInverse.put(null, new SpriteProxy(text, 10, 53, 8, 8));
    }

    public Map<Character, SpriteProxy> initTextDict() {
        Map<Character, SpriteProxy> textDict = new HashMap<>();
        Texture text = TextureCache.get(Gdx.files.internal("text_sheet1.png"));
        char[] alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
        char[] alphabet_lower = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        for (int i = 0; i < 26; i++) {
            textDict.put(Character.valueOf(alphabet_upper[i]), new SpriteProxy(text, 10 + (16 * i), 5, 8, 8));
        }
        for (int i2 = 0; i2 < 26; i2++) {
            textDict.put(Character.valueOf(alphabet_lower[i2]), new SpriteProxy(text, 10 + (16 * i2), 17, 8, 8));
        }
        for (int i3 = 0; i3 < 10; i3++) {
            textDict.put(Character.valueOf(Character.forDigit(i3, 10)), new SpriteProxy(text, 10 + (16 * i3), 29, 8, 8));
        }
        textDict.put(' ', new SpriteProxy(text, 170, 29, 8, 8));
        textDict.put('<', new SpriteProxy(text, 10, 41, 8, 8));
        textDict.put('>', new SpriteProxy(text, 26, 41, 8, 8));
        textDict.put('_', new SpriteProxy(text, 42, 41, 8, 8));
        textDict.put('?', new SpriteProxy(text, 58, 41, 8, 8));
        textDict.put('!', new SpriteProxy(text, 74, 41, 8, 8));
        textDict.put('.', new SpriteProxy(text, 122, 41, 8, 8));
        textDict.put(',', new SpriteProxy(text, 138, 41, 8, 8));
        textDict.put((char) 233, new SpriteProxy(text, 154, 41, 8, 8));
        textDict.put((char) 201, new SpriteProxy(text, 154, 41, 8, 8));
        textDict.put('-', new SpriteProxy(text, 170, 41, 8, 8));
        textDict.put('\'', new SpriteProxy(text, 186, 41, 8, 8));
        textDict.put((char) 236, new SpriteProxy(text, 202, 41, 8, 8));
        textDict.put((char) 146, new SpriteProxy(text, 136, 45, 8, 8));
        textDict.put(null, new SpriteProxy(text, 10, 53, 8, 8));
        return textDict;
    }

    public static FileHandle checkForMods(String path) {
        FileHandle file = Gdx.files.local("mods/" + path);
        if (!file.exists()) {
            file = Gdx.files.internal(path);
        }
        return file;
    }

    public void insertAction(Action actionToInsert) {
        if (actionToInsert != null) {
            for (int i = 0; i < this.actionStack.size(); i++) {
                if (actionToInsert.getLayer().ordinal() >= this.actionStack.get(i).getLayer().ordinal()) {
                    this.actionStack.add(i, actionToInsert);
                    return;
                }
            }
            this.actionStack.add(actionToInsert);
        }
    }

    @Override // com.badlogic.gdx.ApplicationAdapter, com.badlogic.gdx.ApplicationListener
    public void pause() {
    }

    @Override // com.badlogic.gdx.ApplicationAdapter, com.badlogic.gdx.ApplicationListener
    public void render() {
        this.profiler.reset();
        if (this.debugInputEnabled) {
            handleDebuggingInput();
        }
        if (Gdx.input.isKeyJustPressed(141)) {
            toggleFullScreen();
        }
        if (!(this.map == null || this.map.bottomLeft == null || this.map.topRight == null)) {
            if (this.cam.position.x - (this.currScreen.x / 6.0f) < this.map.bottomLeft.x) {
                this.cam.position.x = this.map.bottomLeft.x + (this.currScreen.x / 6.0f);
            }
            if (this.cam.position.x + (this.currScreen.x / 6.0f) > this.map.topRight.x + 16.0f) {
                this.cam.position.x = (this.map.topRight.x - (this.currScreen.x / 6.0f)) + 16.0f;
            }
            if (this.cam.position.y - (this.currScreen.y / 6.0f) < this.map.bottomLeft.y) {
                this.cam.position.y = this.map.bottomLeft.y + (this.currScreen.y / 6.0f);
            }
        }
        this.cam.update();
        this.mapBatch.setProjectionMatrix(this.cam.combined);
        this.mapBatch.begin();
        if (!this.player.dontDrawMapDuringBattle && canUseFrameBuffers && this.mapBatch.getColor().r < 1.0f) {
            this.frameBuffer.begin();
            Gdx.gl.glClear(16384);
            this.temp1 = this.mapBatch.getBlendSrcFunc();
            this.temp2 = this.mapBatch.getBlendDstFunc();
            this.mapBatch.setBlendFunctionSeparate(770, 771, 1, 1);
            this.drawCampfireAuras.step(this);
            this.mapBatch.setBlendFunction(this.temp1, this.temp2);
            this.mapBatch.flush();
            this.frameBuffer.end();
        }
        Gdx.gl.glClear(16384);
        this.prevColor.set(this.mapBatch.getColor());
        if (CycleDayNight.fadeToDay) {
            if (CycleDayNight.fadeToDayAnim.index == 1) {
                this.currCloudTexture = this.cloudTexture;
            }
            this.currSunsetColor.set(CycleDayNight.fadeToDayAnim.currentThing());
        } else if (CycleDayNight.fadeToNight) {
            if (CycleDayNight.animContainer.index == 0) {
                this.currSunsetColor.set(1.0f, 0.9f, 0.5f, 1.0f);
                this.mapBatch.setColor(this.currSunsetColor);
            } else if (CycleDayNight.animContainer.index == 1) {
                this.currSunsetColor.set(0.9f, 0.55f, 0.2f, 1.0f);
                this.mapBatch.setColor(this.currSunsetColor);
            } else if (CycleDayNight.animContainer.index == 2) {
                this.currSunsetColor.set(0.4f, 0.3f, 0.3f, 1.0f);
                this.mapBatch.setColor(this.currSunsetColor);
            } else if (CycleDayNight.animContainer.index == 3) {
                this.currSunsetColor.set(CycleDayNight.animContainer.currentThing());
                this.currCloudTexture = this.nightTexture;
            }
        }
        if (!this.player.dontDrawMapDuringBattle && this.map != null && this.map.tiles == this.map.overworldTiles) {
            this.startPos.set(this.cam.position.x - 576.0f, this.cam.position.y - 384.0f);
            this.endPos.set(this.cam.position.x + 576.0f, this.cam.position.y + 192.0f);
            boolean flipY = false;
            if (this.map.topRight != null && this.cam.position.y > this.map.topRight.y - 384.0f) {
                flipY = true;
            }
            Vector2 currPos = this.startPos.cpy();
            while (currPos.y <= this.endPos.y) {
                this.mapBatch.draw(this.currCloudTexture, (currPos.x - ((this.cam.position.x / 1.5f) % 192.0f)) + this.cloudOffset.x, currPos.y - ((this.cam.position.y / 1.5f) % 192.0f), (float) this.currCloudTexture.getWidth(), (float) this.currCloudTexture.getHeight(), 0, 0, this.currCloudTexture.getWidth(), this.currCloudTexture.getHeight(), false, flipY || this.otherFlipY);
                currPos.x += 192.0f;
                if (currPos.x > this.endPos.x) {
                    currPos.x = this.startPos.x;
                    currPos.y += 192.0f;
                }
            }
            this.otherFlipY = false;
            if (flipY) {
                this.mapBatch.draw(this.islandTexture, (this.cam.position.x + 256.0f) - ((this.cam.position.x / 1.5f) % 1024.0f), (this.map.topRight.y - 5.0f) - ((this.map.topRight.y - this.cam.position.y) / 6.0f));
            }
            this.rippleTimer++;
            if (this.rippleTimer >= 48) {
                this.rippleTimer = 0;
            }
            if (!this.map.timeOfDay.equals("night")) {
                this.cloudOffset.y += 1.0f;
                if (this.cloudOffset.y % 16.0f == 0.0f) {
                    this.cloudOffset.x -= 1.0f;
                    if (this.cloudOffset.x < -192.0f) {
                        this.cloudOffset.x = 0.0f;
                    }
                }
                if (this.cloudOffset.y > 64.0f) {
                    this.cloudOffset.y = 0.0f;
                }
            }
        }
        this.mapBatch.setColor(this.prevColor);
        this.actionStackCopy.clear();
        this.actionStackCopy.addAll(this.actionStack);
        Iterator<Action> it = this.actionStackCopy.iterator();
        while (it.hasNext()) {
            Action action = it.next();
            if (action != null && action.getCamera().equals("map")) {
                try {
                    if (action.firstStep) {
                        action.firstStep(this);
                        action.firstStep = false;
                    }
                    action.step(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        this.mapBatch.end();
        if (this.uiBatch.isDrawing()) {
            this.uiBatch.end();
        }
        this.uiBatch.begin();
        this.actionStackCopy.clear();
        this.actionStackCopy.addAll(this.actionStack);
        Iterator<Action> it2 = this.actionStackCopy.iterator();
        while (it2.hasNext()) {
            Action action2 = it2.next();
            if (action2 != null) {
                try {
                    if (action2.getCamera().equals("gui")) {
                        if (action2.firstStep) {
                            action2.firstStep(this);
                            action2.firstStep = false;
                        }
                        action2.step(this);
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                    System.out.println(action2);
                }
            }
        }
        if (!(!this.dangerousDebugInputEnabled || this.map == null || this.textDict == null)) {
            char[] text = ("FPS " + String.valueOf(Gdx.graphics.getFramesPerSecond())).toCharArray();
            for (int i = 0; i < text.length; i++) {
                this.uiBatch.draw(this.textDict.get(Character.valueOf(text[i])), (float) (104 + (i * 8)), 136.0f);
            }
        }
        this.uiBatch.end();
        if (!PkmnMap.PeriodicSave.isSaveOld()) {
            PkmnMap.PeriodicSave.increaseTimer();
        }
    }

    private void toggleFullScreen() {
        if (this.inFullScreen) {
            Gdx.graphics.setUndecorated(false);
            Gdx.graphics.setWindowedMode(this.oldWindowSize.x, this.oldWindowSize.y);
        } else {
            this.oldWindowSize.set(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            Gdx.graphics.setUndecorated(true);
            Graphics.DisplayMode displayMode = Gdx.graphics.getDisplayMode();
            Gdx.graphics.setWindowedMode(displayMode.width, displayMode.height + 1);
        }
        this.inFullScreen = !this.inFullScreen;
    }

    @Override // com.badlogic.gdx.ApplicationAdapter, com.badlogic.gdx.ApplicationListener
    public void resize(int width, int height) {
        if (height > 0) {
            this.viewport.update(width + (width % 2), height + (height % 2));
            if (Gdx.app.getType() == Application.ApplicationType.Android) {
                int menuHeight = (160 * height) / width;
                this.uiBatch.getProjectionMatrix().setToOrtho2D(0.0f, (float) (-((menuHeight - 144) / 2)), 160.0f, (float) menuHeight);
                System.out.printf("Setting android width = %f, height = %f%n", Float.valueOf(this.cam.viewportWidth), Float.valueOf(this.cam.viewportHeight));
            } else {
                float pixelHeight = 0.0f;
                if (height % 2 == 1) {
                    pixelHeight = 144.0f / ((float) height);
                }
                int menuWidth = (144 * width) / height;
                this.uiBatch.getProjectionMatrix().setToOrtho2D((float) (-((menuWidth - 160) / 2)), 0.0f, (float) menuWidth, 144.0f - pixelHeight);
                int scale = this.scale;
                if (this.cinematic) {
                    scale++;
                }
                Math.round((((float) width) / ((float) scale)) - ((((float) width) / ((float) scale)) % 2.0f));
                Math.round((((float) height) / ((float) scale)) - ((((float) height) / ((float) scale)) % 2.0f));
                System.out.printf("Setting else width = %f, height = %f%n", Float.valueOf(this.cam.viewportWidth), Float.valueOf(this.cam.viewportHeight));
            }
            this.currScreen.set((float) width, (float) height);
        }
    }

    @Override // com.badlogic.gdx.ApplicationAdapter, com.badlogic.gdx.ApplicationListener
    public void resume() {
    }

    public void start() {
        if (drawReflections) {
            insertAction(new DrawReflections(this));
        }
        insertAction(new DrawMap(this.profiler));
        insertAction(new DrawPokemonLowers(this.profiler));
        insertAction(new DrawMapGrass(this.profiler));
        if (this.type != Type.SERVER) {
            insertAction(new PlayerStanding(this, null, false, false));
            insertAction(new DrawBuildTile(this.profiler));
            insertAction(new DrawBuildRequirements(this.profiler));
        }
        insertAction(new MusicController(this));
        insertAction(new DrawMapTrees(this.profiler));
        insertAction(new MoveWater(this));
        insertAction(this.map.upkeepTimers);
        this.playerCanMove = true;
        insertAction(new CycleDayNight(this));
        if (drawOverlays) {
            insertAction(new FogEffect());
        }
        this.player.pokemon.add(new Pokemon("machop", 6));
        if (this.debugInputEnabled) {
            this.player.pokemon.clear();
            this.player.pokemon.add(new Pokemon("breloom", 60));
            this.player.pokemon.add(new Pokemon("rapidash", 60));
            this.player.pokemon.add(new Pokemon("pidgeot", 60, Pokemon.Generation.CRYSTAL));
            this.player.pokemon.add(new Pokemon("rhydon", 46, Pokemon.Generation.CRYSTAL));
            this.player.pokemon.add(new Pokemon("meganium", 46, Pokemon.Generation.CRYSTAL));
            Log.set(2);
        }
        Iterator<Pokemon> it = this.player.pokemon.iterator();
        while (it.hasNext()) {
            it.next().previousOwner = this.player;
        }
        Iterator<Pokemon> it2 = this.player.pokemon.iterator();
        while (it2.hasNext()) {
            Pokemon currPokemon = it2.next();
            if (currPokemon.currentStats.get("hp").intValue() > 0) {
                this.player.currPokemon = currPokemon;
                return;
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Game$SetCamPos.class */
    public static class SetCamPos extends Action {
        Vector2 pos;

        @Override // com.corona.game.Action
        public void step(Game game) {
            game.cam.position.set(this.pos.x, this.pos.y, 0.0f);
            game.actionStack.remove(this);
            game.insertAction(this.nextAction);
        }

        public SetCamPos(Vector2 pos, Action nextAction) {
            super(new Object[0]);
            this.pos = pos;
            this.nextAction = nextAction;
        }
    }

    public static String capitalize(String str) {
        return (str == null || str.isEmpty()) ? str : str.substring(0, 1).toUpperCase(Locale.ROOT) + str.substring(1);
    }

    public void loadSettings(FileHandle file) {
        try {
            Reader reader = file.reader();
            BufferedReader br = new BufferedReader(reader);
            HashMap<String, String> values = new HashMap<>();
            while (true) {
                String line = br.readLine();
                if (line == null) {
                    break;
                }
                String[] vals = line.split("\\/\\/")[0].trim().split("=");
                if (vals.length >= 2) {
                    values.put(vals[0], vals[1]);
                }
            }
            reader.close();
            boolean overwriteFile = false;
            for (int i = 0; i < defaultSettings.length; i++) {
                if (values.get(defaultSettings[i][0]) == null) {
                    overwriteFile = true;
                    values.put(defaultSettings[i][0], defaultSettings[i][1]);
                }
            }
            InputProcessor.keyboardA = Input.Keys.valueOf(capitalize(values.get("keyboard-A")));
            InputProcessor.keyboardB = Input.Keys.valueOf(capitalize(values.get("keyboard-B")));
            InputProcessor.keyboardLeft = Input.Keys.valueOf(capitalize(values.get("keyboard-Left")));
            InputProcessor.keyboardRight = Input.Keys.valueOf(capitalize(values.get("keyboard-Right")));
            InputProcessor.keyboardUp = Input.Keys.valueOf(capitalize(values.get("keyboard-Up")));
            InputProcessor.keyboardDown = Input.Keys.valueOf(capitalize(values.get("keyboard-Down")));
            InputProcessor.keyboardStart = Input.Keys.valueOf(capitalize(values.get("keyboard-Start")));
            InputProcessor.keyboardL = Input.Keys.valueOf(capitalize(values.get("keyboard-L")));
            InputProcessor.keyboardR = Input.Keys.valueOf(capitalize(values.get("keyboard-R")));
            musicDisabled = Boolean.valueOf(values.get("muteMusic")).booleanValue();
            specialPhysicalSplitEnabled = Boolean.valueOf(values.get("specPhysSplitEnabled")).booleanValue();
            photosensitiveMode = Boolean.valueOf(values.get("photosensitiveMode")).booleanValue();
            battleAnims = Boolean.valueOf(values.get("battleAnims")).booleanValue();
            textSpeed = TextSpeed.parse(values.get("textSpeed"));
            float zoom = Float.valueOf(values.get("zoom") + "f").floatValue();
            if (zoom > 0.0f) {
                this.scale = (int) (zoom * ((float) this.scale));
            }
            drawReflections = Boolean.valueOf(values.get("drawReflections")).booleanValue();
            drawOverlays = Boolean.valueOf(values.get("drawOverlays")).booleanValue();
            if (values.containsKey("frameBuffersEnabled")) {
                canUseFrameBuffers = Boolean.valueOf(values.get("frameBuffersEnabled")).booleanValue();
            }
            if (gamepad != null) {
                if (values.get("gamepad-A").equals("B")) {
                    InputProcessor.gamepadA1 = gamepad.getMapping().buttonB;
                    InputProcessor.gamepadA2 = gamepad.getMapping().buttonY;
                } else {
                    InputProcessor.gamepadA1 = gamepad.getMapping().buttonA;
                    InputProcessor.gamepadA2 = gamepad.getMapping().buttonX;
                }
                if (values.get("gamepad-B").equals("A")) {
                    InputProcessor.gamepadB1 = gamepad.getMapping().buttonA;
                    InputProcessor.gamepadB2 = gamepad.getMapping().buttonX;
                } else {
                    InputProcessor.gamepadB1 = gamepad.getMapping().buttonB;
                    InputProcessor.gamepadB2 = gamepad.getMapping().buttonY;
                }
                InputProcessor.gamepadMinAxis = Double.valueOf(values.get("gamepadDeadZone")).doubleValue();
            }
            if (overwriteFile) {
                String settingsString = "";
                for (int i2 = 0; i2 < defaultSettings.length; i2++) {
                    settingsString = settingsString + defaultSettings[i2][0] + "=" + values.get(defaultSettings[i2][0]);
                    if (defaultSettings[i2][0].equals("gamepad-A") || defaultSettings[i2][0].equals("gamepad-B")) {
                        settingsString = settingsString + "     // A or B";
                    }
                    if (i2 < defaultSettings.length - 1) {
                        settingsString = settingsString + IOUtils.LINE_SEPARATOR_WINDOWS;
                    }
                }
                file.writeString(settingsString, false);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /*  JADX ERROR: JadxRuntimeException in pass: BlockProcessor
        jadx.core.utils.exceptions.JadxRuntimeException: Unreachable block: B:6:0x0083
        	at jadx.core.dex.visitors.blocks.BlockProcessor.checkForUnreachableBlocks(BlockProcessor.java:86)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.processBlocksTree(BlockProcessor.java:52)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.visit(BlockProcessor.java:44)
        */
    public static void saveErrorLogAndNotifyUser(String r7, Throwable r8) {
        /*
            java.io.File r0 = new java.io.File
            r1 = r0
            java.lang.String r2 = "error.log"
            r1.<init>(r2)
            r9 = r0
            java.io.PrintWriter r0 = new java.io.PrintWriter     // Catch: IOException -> 0x009b
            r1 = r0
            java.io.FileWriter r2 = new java.io.FileWriter     // Catch: IOException -> 0x009b
            r3 = r2
            r4 = r9
            r5 = 1
            r3.<init>(r4, r5)     // Catch: IOException -> 0x009b
            r1.<init>(r2)     // Catch: IOException -> 0x009b
            r10 = r0
            java.time.OffsetDateTime r0 = java.time.OffsetDateTime.now()     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r11 = r0
            r0 = r10
            r1 = r11
            java.time.format.DateTimeFormatter r2 = java.time.format.DateTimeFormatter.ISO_DATE_TIME     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            java.lang.String r1 = r1.format(r2)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r0.print(r1)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r0 = r10
            java.lang.String r1 = " "
            r0.print(r1)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r0 = r8
            r1 = r10
            com.corona.game.util.StackTraces.writeStackTrace(r0, r1)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            java.io.StringWriter r0 = new java.io.StringWriter     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r1 = r0
            r1.<init>()     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r12 = r0
            r0 = r8
            java.io.PrintWriter r1 = new java.io.PrintWriter     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r2 = r1
            r3 = r12
            r2.<init>(r3)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            com.corona.game.util.StackTraces.writeStackTrace(r0, r1)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r0 = 0
            java.lang.StringBuilder r1 = new java.lang.StringBuilder     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r2 = r1
            r2.<init>()     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r2 = r7
            java.lang.StringBuilder r1 = r1.append(r2)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r2 = r12
            java.lang.String r2 = r2.toString()     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            java.lang.StringBuilder r1 = r1.append(r2)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            java.lang.String r2 = "\n\nPlease report this issue on the PokeWilds discord or Github, and attach "
            java.lang.StringBuilder r1 = r1.append(r2)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r2 = r9
            java.lang.String r2 = r2.getAbsolutePath()     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            java.lang.StringBuilder r1 = r1.append(r2)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            java.lang.String r2 = " to the bug report."
            java.lang.StringBuilder r1 = r1.append(r2)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            java.lang.String r1 = r1.toString()     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            javax.swing.JOptionPane.showMessageDialog(r0, r1)     // Catch: Throwable -> 0x0083, IOException -> 0x009b
            r0 = r10
            r0.close()     // Catch: IOException -> 0x009b
            goto L_0x0098
        L_0x0083:
            r11 = move-exception
            r0 = r10
            r0.close()     // Catch: Throwable -> 0x008c, IOException -> 0x009b
            goto L_0x0095
        L_0x008c:
            r12 = move-exception
            r0 = r11
            r1 = r12
            r0.addSuppressed(r1)     // Catch: IOException -> 0x009b
        L_0x0095:
            r0 = r11
            throw r0     // Catch: IOException -> 0x009b
        L_0x0098:
            goto L_0x00a5
        L_0x009b:
            r10 = move-exception
            java.lang.RuntimeException r0 = new java.lang.RuntimeException
            r1 = r0
            r2 = r10
            r1.<init>(r2)
            throw r0
        L_0x00a5:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.corona.Game.saveErrorLogAndNotifyUser(java.lang.String, java.lang.Throwable):void");
    }
}
